<?php

class Kernel_Form_Value_File_Existing extends Kernel_Form_Value_File 
{
    
    /**
    * Path to the existing file
    * 
    * @var string
    */
    private $_existing_file;
    
    /**
     * Конструктор.
     *
     * @param   string  $name
     */
    public function __construct($name, $existing_path) 
    {
        $this->_existing_file = $existing_path;
        
        parent::__construct($name);
    }
    
    /**
    * Return whether file is already existed
    * 
    * @return boolean
    */
    public function existed() 
    {
        return file_exists($this->_existing_file);
    }
    
    /**
     * Возвращает значение указанного параметра файла
     *
     * @param   string  $field
     * @param   string  $param
     * @return  string
     */    
    
    /**
    * Return existing file param.
    * 
    * @param string $field
    * @param string $param
    * @return string
    */
    protected function _getFileParam($field, $param) 
    {
        switch ($param) 
        {
            case 'name':
                return basename($this->_existing_file);
                break;
                
            case 'tmp_name':
                return $this->_existing_file;
                break;
            
            case 'type': 
                $info = getimagesize($this->_existing_file);
                return $info['mime'];
                break;
            
            case 'size': 
                return filesize($this->_existing_file);
                break;
            case 0:
                return (int)!file_exists($this->_existing_file);
        }
    }
    
}
